<template>
	<view class="body">
		<text class="textStyle">最新情况</text>
		<view class="contentBox">
			<view class="list">
				<view class="img">
					<image :src="'https://crop.lxylw.design'+model.farm.soilphotourl" mode=""></image>
				</view>
				<view class="item">
					农田名称：{{model.farm.soilname}}
				</view>
				<view class="item">
					预警时间：{{model.warn.warntime}}
				</view>
				<view class="item">
					灌溉方式：{{model.farm.watertype}}
				</view>
				<view class="item">
					详细地址：{{model.farm.place}}
				</view>
				<view class="item flex-ja-ac">
					<view class="flex-dc-jc-ac" style="padding-bottom: 20rpx;">
						<u-circle-progress type="warning" :percent="model.farm.curwater" :width="200" :border-width="14"
							duration="2000">
							<view class="u-progress-content">
								<text class='u-progress-info'>{{model.farm.curwater}}%</text>
							</view>
						</u-circle-progress>
						<view style="text-align: center;">当前含水量</view>
					</view>
					<view class="flex-dc-ac">
						<view>
							<u-button type="warning" size="medium" shape="circle" :ripple="true" ripple-bg-color="#EEE"
								:disabled="model.warn.warningdown==0" @click="updateStatus(1)">
								一键灌溉</u-button>
						</view>
						<view style="margin-top: 20rpx;">
							<u-button type="success" size="medium" shape="circle" :ripple="true" ripple-bg-color="#EEE"
								:disabled="model.warn.warningdown==1" @click="updateStatus(0)">
								一键排水</u-button>
						</view>
					</view>
				</view>

				<!-- <view class="item">
					<view class="title">灌溉用水量：</view>
					<view class="content">10 m³/亩</view>
				</view>
				<view class="item">
					<view class="title">未来预测：</view>
					<view class="content">预计在未来三天后需要再次灌溉！</view>
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	import {updateWarn} from "@/common/api/warn.js"
	export default {
		data() {
			return {
				model: null,
				status:false
			}
		},
		onLoad(option) {
			this.model = JSON.parse(option.item)
			console.log(this.model)
		},
		methods: {
			updateStatus(index) {
				if(this.status){
					this.$u.toast("已完成"+(index==0?"排水":"灌溉")+"，无需操作")
				}else{
					this.model.warn.status=1
					this.status = true
					updateWarn(this.model.warn).then(res=>{
						if(res[1].data.result){
							this.$u.toast(res[1].data.detail)
						}
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.body {
		padding: 20rpx;
		background-color: #F1F3F4;
		height: 1218rpx;
	}

	.textStyle {
		margin-left: 24rpx;
		color: #606266;
	}

	.textStyle:after {
		position: absolute;
		width: 8rpx;
		height: 38rpx;
		content: "";
		left: 24rpx;
		border-radius: 10rpx;
		background-color: #606266;
	}

	.contentBox {
		box-sizing: border-box;
		margin-top: 20rpx;
		border-radius: 18rpx;
		min-height: 320rpx;
		width: 100%;
		background-color: #fff;
		color: #606266;
		font-size: 32rpx;

		.list {
			width: 100%;
			box-sizing: border-box;

			.img {
				height: 320rpx;
				overflow: hidden;
				border-radius: 12rpx;
				// box-shadow: 0 10rpx 10rpx #ccc;

				image {
					width: 100%;
				}
			}

			.item {
				padding: 0 20rpx 20rpx;
				margin: 30rpx;
				margin-left: 0;
				display: flex;
			}
		}
	}
</style>
